package shop.services;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import shop.dao.BrandDao;
import shop.pojo.Brand;
import shop.util.SqlSessionUtil;

public class BrandServices {
	//插入数据
	public int getBrandInsert(Brand b){
		SqlSession se =new SqlSessionUtil().getSqlSession();//获取SqlSession
		BrandDao bd = se.getMapper(BrandDao.class);		//实例化接口
		int i=0;
		i=bd.insertBrand(b);	//调用插入方法
		se.commit();			//增删改查需要commit
		return i;
	}
	//查询所有数据
	public List<Brand> selAllBrand(){
		SqlSession se =new SqlSessionUtil().getSqlSession();//获取SqlSession
		BrandDao bd = se.getMapper(BrandDao.class);		//实例化接口
		List<Brand> list = bd.getAllBrand();
		return list;	//返回查询的结果集
	}
	//查询当前页所有数据
		public List<Brand> selPageBrand(int page){
			SqlSession se =new SqlSessionUtil().getSqlSession();//获取SqlSession
			BrandDao bd = se.getMapper(BrandDao.class);		//实例化接口
			List<Brand> list = bd.getPageBrand(page);
			return list;	//返回查询的结果集
		}
	//根据品牌id查询出该品牌的信息
	public Brand selOneBrand(int b_id){
		SqlSession se =new SqlSessionUtil().getSqlSession();//获取SqlSession
		BrandDao bd = se.getMapper(BrandDao.class);		//实例化接口
		return bd.getOneBrand(b_id);	//返回
	}
	//修改品牌的信息
	public int uptOneBrand(Brand brand){
		SqlSession se =new SqlSessionUtil().getSqlSession();//获取SqlSession
		BrandDao bd = se.getMapper(BrandDao.class);		//实例化接口
		int i = bd.updateBrand(brand);
		se.commit();
		return i;
	}
	//删除品牌
	public void deleteBrand(int b_id){
		SqlSession se =new SqlSessionUtil().getSqlSession();//获取SqlSession
		BrandDao bd = se.getMapper(BrandDao.class);		//实例化接口
		bd.delOneBrand(b_id);
		se.commit();
	}
}
